package com.pei.Servlet;


import com.pei.Service.Impl.userServiceImpl;
import com.pei.Service.userService;
import com.pei.entity.user;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by dell on 2018/8/6.
 */
@WebServlet(name = "finduserServlet")
public class finduserServlet extends HttpServlet {
    int yenum=0;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        userService service=new userServiceImpl();
        request.setCharacterEncoding("utf-8");
        String name="";
        if (request.getParameter("username")!=null){
            name=request.getParameter("username");
        }
        int jinum=5;
        if ( request.getParameter("limit")!=null) {
            yenum = Integer.parseInt(request.getParameter("limit"));
        }else{
            yenum=0;
        }
        if (yenum<0){
            yenum=0;
        }
        if (Integer.parseInt(request.getParameter("idd"))==1) {
            int sum=service.findcountuser(3);
            int max=(sum+jinum-1)/jinum;
            if (yenum*jinum>max-1){
                yenum=max-1;
            }
            List<user> slist= service.finduser(name,3,yenum*jinum,jinum);
            request.setAttribute("slist",slist);
            request.setAttribute("yenum",yenum);
            if (Integer.parseInt(request.getParameter("id")) == 1) {
                request.getRequestDispatcher("echarts2.jsp").forward(request, response);
            } else if (Integer.parseInt(request.getParameter("id")) == 2) {
                request.getRequestDispatcher("echarts22.jsp").forward(request, response);
            } else if (Integer.parseInt(request.getParameter("id")) == 3) {
                request.getRequestDispatcher("echarts21.jsp").forward(request, response);
            }
        }
        if (Integer.parseInt(request.getParameter("idd"))==2){
            int sum=service.findcountuser(6);
            int max=(sum+jinum-1)/jinum;
            if (yenum*jinum>max-1){
                yenum=max-1;
            }
            List<user> slist= service.finduser(name,6,yenum*jinum,jinum);
            request.setAttribute("slist",slist);
            if (Integer.parseInt(request.getParameter("id")) == 1) {
                request.getRequestDispatcher("echarts211.jsp").forward(request, response);
            } else if (Integer.parseInt(request.getParameter("id")) == 2) {
                request.getRequestDispatcher("echarts212.jsp").forward(request, response);
            } else if (Integer.parseInt(request.getParameter("id")) == 3) {
                request.getRequestDispatcher("echarts213.jsp").forward(request, response);
            }
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
